// pages/my/my.js
Page({
	data: {
    user: {
      avatarUrl: "cloud://cloud1-8g4hfxry284035d7.636c-cloud1-8g4hfxry284035d7-1365437610/images/mine/头像.jpg",
      qrcode: "cloud://cloud1-8g4hfxry284035d7.636c-cloud1-8g4hfxry284035d7-1365437610/images/mine/QR_code.png",
      nickName: '',
    },
		showPopup: false,
    popupIn: false,
    stats: [
      { label: '星币', value: 0 },
      { label: '电子金币', value: 0 },
      { label: '星票', value: 0 },
      { label: '优惠券', value: 1 },
      { label: '星星票', value: 0 },
      { label: '娃娃点', value: 0 },
		],
		serviceList: [
      { name: "全部订单", icon: "cloud://cloud1-8g4hfxry284035d7.636c-cloud1-8g4hfxry284035d7-1365437610/images/mine/Member_Tasks/order.png" },
      { name: "储值记录", icon: "cloud://cloud1-8g4hfxry284035d7.636c-cloud1-8g4hfxry284035d7-1365437610/images/mine/Member_Tasks/record.png" },
      { name: "我的预约", icon: "cloud://cloud1-8g4hfxry284035d7.636c-cloud1-8g4hfxry284035d7-1365437610/images/mine/Member_Tasks/appointment.png" },
      { name: "个人资料", icon: "cloud://cloud1-8g4hfxry284035d7.636c-cloud1-8g4hfxry284035d7-1365437610/images/mine/Member_Tasks/individual.png" },
      { name: "联系门店", icon: "cloud://cloud1-8g4hfxry284035d7.636c-cloud1-8g4hfxry284035d7-1365437610/images/mine/Member_Tasks/record.png" },
      { name: "设置", icon: "cloud://cloud1-8g4hfxry284035d7.636c-cloud1-8g4hfxry284035d7-1365437610/images/mine/Member_Tasks/setting.png" }
		],
		clubList: [
			{
				name: '任务',
				icon: 'cloud://cloud1-8g4hfxry284035d7.636c-cloud1-8g4hfxry284035d7-1365437610/images/mine/Member_Club/task.png',
				url: '/pages/mine/task/task'
			},
			{
				name: '分销',
				icon: 'cloud://cloud1-8g4hfxry284035d7.636c-cloud1-8g4hfxry284035d7-1365437610/images/mine/Member_Club/distribution.png',
				url: '/pages/mine/distribution/distribution'
			},
			{
				name: '团购核销',
				icon: 'cloud://cloud1-8g4hfxry284035d7.636c-cloud1-8g4hfxry284035d7-1365437610/images/mine/Member_Club/purchase.png',
				url: '/pages/mine/team-purchase/index'
			}
		],
  },  
	goToClubPage(e) {
		const index = e.currentTarget.dataset.index;
		const url = this.data.clubList[index].url;
	   console.log(url);
		if (url) {
			wx.navigateTo({ url });
		} else {
			wx.showToast({ title: '未配置跳转地址', icon: 'none' });
		}
	},	
	goTostoredRecords(){
	  wx.navigateTo({
			url: '/pages/mine/vip/storedRecords/storedRecords',
		})
	},
  openPopup() {	
    const comp = this.selectComponent('#popupCard');
    if (comp) {
      comp.openPopup();
    } else {
      console.error('没有找到popupCard组件');
    }
  },
	goToOverlay() {
    wx.navigateTo({
      url: '/pages/qrcodePage/qrcodePage'
    });
	},
	goToWelfare(){
		wx.navigateTo({
			url: '/pages/mine/welfare/welfare',
		})
	},
  getUserInfo() {
    wx.getUserInfo({
      lang: 'zh_CN',
      success: (res) => {
        console.log('用户信息:', res.userInfo);
        this.setData({
          // this.avatarUrl:res.userInfo.avatarUrl,
          // user.nickName: res.userInfo.nickName
          user: {
            ...this.data.user,
            avatarUrl: res.userInfo.avatarUrl,
            nickName: res.userInfo.nickName,
          }
        });
        console.log(this.data.user);
      },
      fail: (err) => {
        console.log('获取用户信息失败:', err);
      }
    });
  },
	onServiceClick(e) {
		const index = e.currentTarget.dataset.index;
	
		const pages = [
			'/pages/mine/vip/orderCenter/orderCenter',       // 全部订单
			'/pages/mine/vip/storedRecords/storedRecords',   // 储值记录
			'/pages/mine/vip/appointment/appointment',       // 我的预约
			'/pages/mine/vip/profile/profile',               // 个人资料
			'/pages/mine/vip/contactStore/contactStore',     // 联系门店
			'/pages/mine/vip/settings/settings'              // 设置
		];
	
		if (pages[index]) {
			// console.log(pages[index])
			wx.navigateTo({		
				url: pages[index]
			});
		} else {
			wx.showToast({
				title: '页面路径未配置',
				icon: 'none'
			});
		}
	},	
	onLoad(options) {},
});